package com.example.sonone.controller;


import com.example.sonone.service.AAservice;
import com.example.sonone.service.ICommonFileUploadService;
import com.example.sonone.service.impl.StartTaskServiceImpl;
import com.example.sonone.util.SpringBeanFactory;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.PostConstruct;
import javax.xml.ws.spi.http.HttpContext;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@RestController
@RequestMapping("/aaaaaa")
public class TestController {

    ICommonFileUploadService iCommonFileUploadService;

    @RequestMapping("abst")
    public void tt() {
        iCommonFileUploadService = SpringBeanFactory.getBean("StartTaskServiceImpl");
//        StartTaskServiceImpl startTaskService=new
        iCommonFileUploadService.uploadOss(null, null, true);
    }
    @RequestMapping("ddddddd")
    public String  ddddddd() {
        return "abc";
    }

    AAservice aAservice;



/*    @PostConstruct
    public void init() {
        aAservice = context.getBean(SimpleMachineDiscovery.class);
    }*/


    @RequestMapping("/bbb")
    public boolean test(@RequestParam Map<String, Object> params,
                        @RequestParam(value = "file", required = false) MultipartFile file) {


        return true;
    }


    public static void main(String[] args) {
        List<Map<String, String>> hashMaps = Lists.newArrayList();
        Map<String, String> map1 = new HashMap<>();
        Map<String, String> map2 = new HashMap<>();
        Map<String, String> map3 = new HashMap<>();
        hashMaps.add(map1);
        hashMaps.add(map2);
        hashMaps.add(map3);
        map1.put("name", "yuwen"); map1.put("code", "01");

        map2.put("name", "shuxu"); map2.put("code", "02");

        map3.put("name", "yingyu");map3.put("code", "03");
        // k: 原来name的值 v:原来 code的 值
        Map<String, String> expectedMap
                = hashMaps.stream().collect(Collectors.toMap(m -> m.get("name"), m -> m.get("code")));

        // k: 原来的k v:原来的v
        Map<String, String> collect = hashMaps.stream()
                .map(Map::entrySet)
                .flatMap(Collection::stream)
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        System.out.println(collect);
    }

}
